<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <script src="/js/jquery-3.2.1.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/layui/lay/modules/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="/layui/css/modules/layer/default/layer.css">
    <style>
        .page {
            background-image: url("/img/bc.jpg");
            position: absolute;
            width: 100%;
            height: 100%;
            background-repeat: no-repeat;
            background-size: 100% 100%;
        }

        .middle {
            width: 100%;
            height: 70%;
            text-align: center;
            display: flex;
            align-items: center;
        }

        .middle > div {
            width: 30%;
            background-color: white;
            margin: 0 auto;
            padding: 20px 10px;
            border-radius: 10px;
            box-shadow: black 0px 0px 5px;
        }
    </style>
</head>
<body>
<div class="page">
    <#include "/head.html">
    <div class="middle">
        <div>
            <div style="width: 100%;color: #009688;font-size: 20px">管理员注册</div>
            <hr class="layui-bg-green">
            <form class="layui-form" action="" method="post" onsubmit="return sunbmitForm()">
                <div class="layui-form-item" style="display: flex;justify-content: flex-start">
                    <div style="border: solid #e6e6e6 1px;display: flex;align-items: center;border-right: none;width: 10%;justify-content: center">
                        <i class="layui-icon">&#xe678;</i>
                    </div>
                    <input style="margin: 0" type="text" name="manager_tel" id="manager_tel" lay-verType="tips"
                           lay-verify="phone" placeholder="请输入手机号码"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item" style="display: flex;justify-content: space-between">
                    <div style="border: solid #e6e6e6 1px;display: flex;align-items: center;border-right: none;width: 9%;justify-content: center">
                        <i class="layui-icon">&#xe679;</i>
                    </div>
                    <input style="margin: 0;width: 60%" type="text" name="phoneCode" lay-verType="tips"
                           lay-verify="PhoneCode" placeholder="请输入四为短信验证码"
                           autocomplete="off" class="layui-input" maxlength="4">
                    <a class="layui-btn" id="sendPhoneCodeButton" style="width: 30%">
                        <i class="layui-icon">&#xe609;</i> <span id="sendPhoneCodeButtonText">发送验证码</span>
                    </a>
                </div>
                <div class="layui-form-item" style="display: flex;justify-content: flex-start">
                    <div style="border: solid #e6e6e6 1px;display: flex;align-items: center;border-right: none;width: 10%;justify-content: center">
                        <i class="layui-icon">&#xe673;</i>
                    </div>
                    <input style="margin: 0" type="password" name="manager_password" id="manager_password"
                           lay-verType="tips" lay-verify="password" placeholder="请输入密码"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item" style="display: flex;justify-content: flex-start">
                    <div style="border: solid #e6e6e6 1px;display: flex;align-items: center;border-right: none;width: 10%;justify-content: center">
                        <i class="layui-icon">&#xe673;</i>
                    </div>
                    <input style="margin: 0" type="password" name="manager_password2" id="manager_password2"
                           lay-verType="tips" lay-verify="password" placeholder="请再次输入密码"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button id="formDemo" class="layui-btn" lay-submit lay-filter="formDemo" style="width: 100%">登录
                    </button>
                </div>
            </form>
        </div>
    </div>
    <#include "/footer.html">
</div>
</body>
<script>
    $(".layui-nav>li:nth-child(2)").addClass("layui-this");
</script>
<script>
    $("#sendPhoneCodeButton").click(function () {
        var manager_tel = $("#manager_tel").val();
        if (!(/^1[3|4|5|8|7|9][0-9]\d{4,8}$/.test(manager_tel))) {
            $("#manager_tel").focus();
            layer.msg('手机号码格式不正确', {icon: 5});
            return false;
        }
        //发送验证码
        $.ajax({
            type: 'POST',
            url: "/Login/managerLoginPhoneCode",
            data: {"manager_tel": manager_tel},
            success: function (res) {
                layer.msg(res.message);
            },
            error: function (res) {
                console.log(res);
            }
        });

        var time = 10;
        $("#sendPhoneCodeButton").addClass("layui-btn-disabled");
        var interval = setInterval(function () {
            $("#sendPhoneCodeButtonText").html(time);
            if (time == 0) {
                $("#sendPhoneCodeButtonText").html("发送验证码");
                $("#sendPhoneCodeButton").removeClass("layui-btn-disabled");
                clearInterval(interval);
            }
            time--;
        }, 1000)
    });

    //不让表单提交
    function sunbmitForm() {
        return false;
    }

    //导航兰样式
    $(".layui-nav>li:last-child").addClass("layui-this");
    $(document).on('keyup', function (e) {
        var theEvent = window.event || e;
        var code = theEvent.keyCode || theEvent.which;
        if (code == 13) {
            $("#formDemo").click();
        }
        return false;
    })
</script>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function () {
        var element = layui.element;
        //…
    });
</script>
<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            if ($("#manager_password").val() != $("#manager_password2").val()) {
                $("#manager_password2").focus();
                layer.msg('两次密码不一致！', {icon: 5});
                return false;
            }
            $.ajax({
                type: 'POST',
                url: "/login/managerzhuce",
                data: data.field,
                success: function (res) {
                    layer.alert(res.message);
                    if (res.statusCode == "0") {
                        location.href = "/";
                    }
                }
            });
            return false;
        });
        form.verify({
            password: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ],
            PhoneCode: [
                /^[\S]{4}$/
                , '请输入正确的四位短信验证码'
            ]
        });
        form.on('switch', function (data) {
            $(data.othis).siblings('input').remove();
            $(data.othis).after('<input type="hidden" name=' + $(data.elem).attr('name') + ' value=' + (data.elem.checked ? 'on' : 'off') + '>');
        });
    });
</script>
<script>
    // layer.alert("layui加载成功!");
</script>
</html>